package com.bdqn.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.pojo.Role;
import com.bdqn.pojo.User;
import com.bdqn.service.RoleService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/role")
public class RoleController {
    @Resource
    private RoleService roleService;
    @RequestMapping("/list")
    public String list(Model model,String roleName,Long pageIndex){
        // 当前要查询的页码，如果是null则设置为默认查第1页
        pageIndex = pageIndex == null ? 1 : pageIndex;
        // 分页查询用户列表
        Page page = new Page(pageIndex, 5L);
        Page<Role> rolePage = roleService.findPage(page,roleName);

        // 设置数据到作用域
        model.addAttribute("roleName", roleName); // 数据回显
        model.addAttribute("rolePager", rolePage);
        return "role/list";
    }
}
